/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 * View all members belong to a group
 * @author User1
 */
public class GroupAllMembers extends HttpServlet {
   
    String[] memberNames = {"Karl", "David", "Rodrigo", "Jinlin", "Kyu"};
    String[] memberEmails = {"karl@hotmail.com", "david@yahoo.com", "rodrigo@hotmail.com", "jinlin@hotmail.com", "kyu@hotmail.com"};
   
    
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
          
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet GroupAllMembers</title>");  
            generateInlineJS(out);
            CSSGenerator.generateNewsGroupMainPageInlineCSS(out);
            out.println("</head>");
            out.println(
                    "<body>" + 
                    "<center>");
         
            out.println( 
                    "<table width=\"40%\" border>" +
                    "<tr>" +
                    "<th colspan=\"3\">Group Members</th>" +
                    "</tr>");
            
            for(int i = 0; i < memberNames.length; i++)
            {
                out.println(
                        
                     "<form action=\"MAILTO:" + memberEmails[i] + "\" method=\"post\" enctype=\"text/plain\">" +
                        "<tr>" +
                        /*member name hyperlink to his/her main page*/
                        "   <td align=\"center\">"+
                        "   <a href=\"UserServlet?" + // TODO: change to the user's mainpage
                            memberEmails[i] + 
                            "\" target=\"_blank\">"+
                            memberNames[i] + "</a>" +
                        "   </td>" +
                        /*e-mail address of the user*/
                        "   <td>" + 
                            memberEmails[i] + // TODO: send e-mail to the user
                        "   </td>" +
                        "   <td align = \"right\"> " +
                        /*button to send e-mail*/
                        "   <input type=\"submit\" value=\"Send\">" +
                        "   </td>" +
                        "</tr>" +
                        "</form>"
                        );
            }
            
            out.println(
                     "</table>" + 
                     "</center>" 
                     );
            
            out.println("</body>");
            out.println("</html>");
         
        } finally { 
            out.close();
        }
    } 

     private void generateInlineJS(PrintWriter out)
    {
        out.println(
                 "<script language=\"javascript\"> " +
         "function loadwindow(target)" +
         "{" +
         "       window.open(target,\"\",\"width=800,height=600,status=1,menubar=0,resizable=1\");" +      
         "}" +
         "</script>"
       );
    }
     
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
